package br.com.wss.model;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import br.com.wss.R;

public class AdapterList extends BaseAdapter {
	private LayoutInflater mInflater;
	private List<String> mTitles;
	private List<String> mDialogue;

	public AdapterList(Context context, List<String> sumario, List<String> txt) {
		mInflater = LayoutInflater.from(context);
		this.mTitles = sumario;
		this.mDialogue = txt;
	}

	/**
	 * The number of items in the list is determined by the number of speeches
	 * in our array.
	 * 
	 * @see android.widget.ListAdapter#getCount()
	 */
	public int getCount() {
		return mTitles.size();
	}

	/**
	 * Since the data comes from an array, just returning the index is sufficent
	 * to get at the data. If we were using a more complex data structure, we
	 * would return whatever object represents one row in the list.
	 * 
	 * @see android.widget.ListAdapter#getItem(int)
	 */
	public Object getItem(int position) {
		return position;
	}

	/**
	 * Use the array index as a unique id.
	 * 
	 * @see android.widget.ListAdapter#getItemId(int)
	 */
	public long getItemId(int position) {
		return position;
	}

	/**
	 * Make a SpeechView to hold each row.
	 * 
	 * @see android.widget.ListAdapter#getView(int, android.view.View,
	 *      android.view.ViewGroup)
	 */
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout row;
		if (convertView == null) {
			row = (LinearLayout) mInflater.inflate(R.layout.row_expandable,
					null);
		} else {
			row = (LinearLayout) convertView;
		}

		TextView title = (TextView) row.findViewById(R.id.row_exp_title);
		title.setText(mTitles.get(position));
		TextView txt = (TextView) row.findViewById(R.id.row_exp_txt);
		txt.setText(mDialogue.get(position));

		int visible = txt.getVisibility() == View.VISIBLE ? View.VISIBLE
				: View.GONE;
		txt.setVisibility(visible);

		return row;
	}

}
